package com.oss.controller.system;

import com.oss.common.BaseResponse;
import com.oss.dto.role.*;
import com.oss.service.system.RoleService;
import com.oss.vo.role.RoleDetailVO;
import com.oss.vo.role.RoleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author chengqiang
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    RoleService roleService;

    /**
     * 根据角色ID获取角色信息
     * @param dto 入参
     * @return 返回值
     */
    @RequestMapping("/getRoleById")
    public BaseResponse<RoleDetailVO> getRoleById(@RequestBody @Valid GetOneRoleDto dto){
        return roleService.getOneById(dto.getRoleId());
    }
//    @RequestMapping("/selectByPage")
//    public BaseResponse<IPage<RoleVO>> selectByPage(@RequestBody @Valid RolePageDto dto){
//        return BaseResponse.success(roleService.selectByPage(dto));
//    }
    @RequestMapping("/listAll")
    public BaseResponse<List<RoleVO>> listAll(@RequestBody RolePageDto dto){
        return BaseResponse.success(roleService.listAll(dto));
    }
    @RequestMapping("/addRole")
    public BaseResponse<String> addRole(@RequestBody @Valid RoleAddDto dto){
        return roleService.addRole(dto);
    }
    @RequestMapping("/updateRole")
    public BaseResponse<String> updateRole(@RequestBody @Valid RoleUpdateDto dto){
        return roleService.updateRole(dto);
    }
    @RequestMapping("/deleteRole")
    public BaseResponse<String> deleteRole(@RequestBody @Valid RoleDeleteDto dto){
        return BaseResponse.success(roleService.deleteRole(dto));
    }
}
